//
//  answerQuestionViewController.m
//  YuErmuYing
//
//  Created by Tiancheng on 16/9/6.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "answerQuestionViewController.h"
#import "nextDetailZhuanJiaViewController.h"
#import "HttpRequest.h"
#import "zhuanJiaJiangTang.h"
#import "nextDetail.h"
#import "Macros.h"
#import "TCLYUser.h"

@interface answerQuestionViewController ()
@property (weak, nonatomic) IBOutlet UIView *headerView;
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@end

@implementation answerQuestionViewController

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden=YES;
    self.tabBarController.tabBar.hidden=YES;
}
-(void)viewDidLoad
{
    [super viewDidLoad];
    self.headerView.backgroundColor=[UIColor colorWithRed:244/255.0 green:143/255.0 blue:177/255.0 alpha:1.0];
    self.label.hidden=NO;
    //添加手势
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer  alloc ] initWithTarget:self action : @selector (onClick:)];
    self.label.userInteractionEnabled = YES;
    [self.label addGestureRecognizer:tap];
    UITapGestureRecognizer *tap1=[[UITapGestureRecognizer  alloc ] initWithTarget:self action : @selector (onClick000:)];
    self.textView.tag=2;
    self.textView.userInteractionEnabled = YES;
    [self.textView addGestureRecognizer:tap1];
}

//从服务器获取数据
-(void)getDataFromNet
{
    zhuanJiaJiangTang *zjjt=[zhuanJiaJiangTang shardeManager];
    NSString*urlString=[NSString stringWithFormat:@"http://112.74.114.1/Parenting/index.php/api/note/publish"];
    NSMutableDictionary *parameters=[NSMutableDictionary dictionary];
    parameters[@"uid"]=userID;
    parameters[@"note_id"]=zjjt.note_id;
    parameters[@"comment_body"]=self.textView.text;
    NSLog(@"zjjt.note_id=%@",zjjt.note_id);
    NSLog(@"self.textView.text=%@",self.textView.text);

    HttpRequest *httpRequest=[HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlString parameters:parameters success:^(id responseObject)
     {
         id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
         //获取数组
         int msg=[[json objectForKey:@"msg"]intValue];
         if (msg==200)
         {
             nextDetailZhuanJiaViewController *ndzjvc=self.navigationController.viewControllers[2];
             [self.navigationController popToViewController:ndzjvc animated:YES];
         }
          NSLog(@"json=%@",json);
     } failure:^(NSError *error) {
         NSLog(@"error=%@",error);
     }];
}
-(void)onClick:(UIButton*)sender
{
    self.label.hidden=YES;
    [self.textView becomeFirstResponder];
}
-(void)onClick000:(UITapGestureRecognizer*)sender
{
    if (sender.view.tag==2)
    {
        self.label.hidden=YES;
        [self.textView becomeFirstResponder];
    }
}
- (IBAction)goBack:(id)sender
{
    nextDetailZhuanJiaViewController *ndzjvc=self.navigationController.viewControllers[2];
    [self.navigationController popToViewController:ndzjvc animated:YES];
}
- (IBAction)commitAnswer:(id)sender
{
    [self getDataFromNet];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
